include<ub.scad>; //⇒ v.gd/ubaer or https://github.com/UBaer21/UB.scad
/*[Hidden]*/
designVersion="1.0";
designer="Ulrich Bär";
license="CC0";
useVersion=24.022;//(sites.google.com/site/ulrichbaer)
assert(Version>=useVersion,str("lib version ",Version," detected, include ",useVersion," ub.scad library‼ ⇒http://v.gd/ubaer"));
/*[Basics]*/
nozzle=.2;
bed=false;
pPos=[0,0];
info=false;
name=undef;

/*[Adjuster]*/
pitch=.5;
diameter=6;
length=50;

T(printPos){
Adj(pitch,diameter,length);
}

T(printPos)T(20)Adj(pitch,diameter,length,opt=1);
if($preview)T(printPos)T(0,-22+15*1,3.5/2)R(-90)Cut()Adj(pitch,diameter,length,opt=1);



module Adj(p,d,l,w=22,opt=0,dicke=1,fDicke=1){
p1=1.25;

p2=p1+p;
d1=d;
d2=d;
gh=.65;
threadL=5;
dist=threadL*2/3;
l=l-dist;
h=min(d-gh*2,sin(50)*d);
rotations= (l-d+.5)/(p1+p2);

l1=rotations*p1;
l2=rotations*p2;
range=(l1-threadL)/p1*p;

echo(range=range,l1+l2,h=h);

if(!opt){
  intersection(){
    Tz(h/2)union(){
      R(90)Gewinde(dn=d1,p=p1,h=l1,center=0,tz=dist/2+(l2-l1)/2,mantel=0,breite=.25,kern=d1-gh*2,fs=.3);
      R(-90)Gewinde(dn=d2,p=p2,h=l2,center=0,tz=dist/2-(l2-l1)/2,mantel=0,breite=.5,kern=d2-gh*2,fs=.3);
    }
    cylinder(h,d=500,$fn=6);
  }
  *Roof(h,[1,1]*dicke/3)Rand(dicke)Rand(.5)Quad(15,l+dist-dicke*2);
  MKlon(ty=(l+dist-d/2)/2)Prisma(w,d/2,r=d/5,z=h);
  Roof(h,[1,1]*dicke/3)intersection(){MKlon(w/2-3)
    Welle(e=l/6+2,r=1.5,rand=fDicke);
    square([w+10,l+dist-d/2],true);
    }
}
if(opt){ // nut
 h=l2+threadL-p2-2-dicke*1.5+range;//l1-1-dicke*1.5+dist;
 threadL2=min(4*p2,h-l1);
 echo(hNut=h);
 d=max(d1,d2)+(spiel+dicke)*2+.1;
  Gewinde(dn=d1+spiel*2,p=p1,h=threadL,center=0,tz=0.5,innen=true,mantel=d-.1,kern=d1+spiel*2-gh*2);
  Color()Gewinde(dn=d2+spiel*2,p=p2,h=threadL2,center=0,tz=h-threadL2-.5,innen=true,mantel=d-.1,breite=p2/2-.65,kern=d2+spiel*2-gh*2);
  Roof(h,[1,1]*dicke/3)Ring(d=d,dicke=dicke-.05);
  Tz(h/2)Polar(9)LinEx(h-5,center=true,end=true)Vollwelle(.5,h=1,extrude=d/2-.15,x0=d/2-dicke/2,xCenter=-1);
  Tz(h-5)RotEx()Vollwelle(.5,h=.5,extrude=d/2,x0=d/2-dicke/2,xCenter=-1);
  Tz(h-2.5)RotEx()Vollwelle(.5,h=.75,extrude=d/2,x0=d/2-dicke/2,xCenter=-1);
}

}



// version Info
if(string2num(designVersion[2])>0)T(1,-1)color("navy")linear_extrude(.1)Seg7(str(designVersion),h=1,spiel=0.01,b=.05,ratio=0.5,center=true,name=0);